package com.it.springbootjpa.controller;

import com.it.springbootjpa.domain.Contract;
import com.it.springbootjpa.query.ContractQury;
import com.it.springbootjpa.service.ContractService;
import com.it.springbootjpa.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
public class ContractController {
    @Autowired
    ContractService contractService;
    @GetMapping("save")
    public void save(){
        Contract contract= new Contract();
        contract.setContractNum(12345L);
        contract.setContractStatus(true);
        contract.setName("张三");
        contract.setContractPrice(BigDecimal.valueOf(6000));
        contractService.save(contract);
    }
    @GetMapping("delete")
    public void delete(Contract contract){
        contractService.delete(contract);
    }
    @GetMapping("findAll")
    public ResultUtil findAll(){
        List<Contract> contracts = contractService.findAll();
        return contracts!=null?new ResultUtil(ResultUtil.SUCCESS,"查询成功！",contracts):new ResultUtil(ResultUtil.FAIL,"查询失败");
    }
    @GetMapping("findByConditon")
    public ResultUtil findByConditon(ContractQury contractQury){
        List<Contract> contracts = contractService.findByCondition(contractQury);
        return contracts!=null?new ResultUtil(ResultUtil.SUCCESS,"查询成功！",contracts):new ResultUtil(ResultUtil.FAIL,"查询失败");
    }
}
